package org.example.examfx02.controller;

import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.scene.control.*;
import org.example.examfx02.entity.Teacher;
import org.example.examfx02.tool.StringUtil;
import org.example.examfx02.tool.SystemData;

public class AddTeaViewController {
    SystemData sys = SystemData.getInstance();
    @FXML
    TextField teaId;
    @FXML
    ChoiceBox teaLevel;
    ObservableList<String> chooseList;
    @FXML
    TextField teaName;
    @FXML
    TextField teaPassword;
    @FXML
    Button admitBtn;
    @FXML
    Label label;
    public void initialize(){
        label.setVisible(false);
        chooseList = FXCollections.observableArrayList();
        chooseList.add("教授");
        chooseList.add("副教授");
        chooseList.add("讲师");
        teaLevel.setItems(chooseList);
    }
    public void admit(){
        String id = teaId.getText();
        String level = teaLevel.getValue().toString();
        String name = teaName.getText();
        String password = teaPassword.getText();
        if(StringUtil.isEmpty(id)){
            label.setText("ID不能为空");
            label.setVisible(true);
            return ;
        }else if(sys.getUserGroup().getTeacherByID(id)!=null){
            label.setText("ID已被注册");
            label.setVisible(true);
            return ;
        }
        if(StringUtil.isEmpty(level)){
            label.setText("班级不能为空");
            label.setVisible(true);
            return ;
        }
        if(StringUtil.isEmpty(name)){
            label.setText("姓名不能为空");
            label.setVisible(true);
            return ;
        }
        if(StringUtil.isEmpty(password)){
            label.setText("密码不能为空");
            label.setVisible(true);
            return ;
        }
        label.setVisible(false);
        Teacher teacher = new Teacher(id,name,level,password,true);
        SystemData.getInstance().getUserGroup().getTeachers().add(teacher);
    }
}
